package day015;

/**
 * @author success
 * @version 1.0
 * @description:本类用来演示:线程之间的礼让
 * @date 2019/8/3 0003
 */
public class YieldDemo {
    public static void main(String[] args) {
        new Y2().start();
        new Y2().start();
    }
}
class Y2 extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {

            if(i==3){
                //线程之间的礼让 - 暂停当前正在执行的线程对象，并执行**"其他线程"
                Thread.yield();
            }
            System.out.println(Thread.currentThread().getName()+"->"+i);

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}